package com.aiyige.page.publish.info;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.page.publish.info.model.PublishInfoFormModel;
import com.aiyige.utils.AccountUtil;
import com.aiyige.utils.GlideUtil;
import com.aiyige.utils.widget.articleview.ArticlePreview;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = ARouterConfig.PublishInfoPreviewPage)
public class PublishInfoPreviewPage extends AppCompatActivity {

    @BindView(R.id.titleTv)
    TextView titleTv;
    @BindView(R.id.articlePreview)
    ArticlePreview articlePreview;

    @Autowired
    PublishInfoFormModel formModel;
    View publishInfoPreviewPageHeader;
    //Header
    TextView infoTitleTv;
    ImageView avatarIv;
    TextView userNameTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish_info_preview_page);
        ButterKnife.bind(this);
        ARouter.getInstance().inject(this);
        titleTv.setText(R.string.info_preview);
        initHeader();
        articlePreview.setData(formModel.getArticleNodeList());
    }

    public void initHeader() {
        publishInfoPreviewPageHeader = articlePreview.addHeader(R.layout.publish_info_preview_page_header);
        infoTitleTv = (TextView) publishInfoPreviewPageHeader.findViewById(R.id.infoTitleTv);
        avatarIv = (ImageView) publishInfoPreviewPageHeader.findViewById(R.id.avatarIv);
        userNameTv = (TextView) publishInfoPreviewPageHeader.findViewById(R.id.userNameTv);
        GlideUtil.with(this)
                .loadAvatar(AccountUtil.getCurrentUser().getAvatar())
                .into(avatarIv);
        userNameTv.setText(AccountUtil.getCurrentUser().getAccount());
        infoTitleTv.setText(formModel.getTitle());
    }


    @OnClick({R.id.titleBackBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titleBackBtn:
                finish();
                break;
            default:
                break;
        }
    }
}
